<?php

namespace App\Http\Requests\Api\v2;

use App\Http\Requests\CommonRequest;

class LiveGoodsRequest extends CommonRequest
{

    public $scenes = [
        'store' => "name,coverImgUrl,priceType,price,goodsId,auditId,successText,goodsType,address_id",
        'goods' =>"shareUserId,goodId",
    ];

    public function rules()
    {
        $data = request()->all();

        return [
            'name'        => ['required'],
            'coverImgUrl' => ['required'],
            'priceType'   => ['required'],
            'price'       => [
                'required',
                function ($a, $v, $f) use ($data) {
                    if ($data['priceType'] == 3 && $data['price2'] <= 0) {
                        return $f('现在价格不能为空！');
                    }
                },
            ],
            'price2'      => ['required'],
            'url'         => ['required'],
            'goodsId'     => ['required'],
            'auditId'     => ['required'],
            'successText' => ['required'],
            'shareUserId' => ['required'],
            'goodId'    => ['required'],
            'goodsType'   => [
                'required',
                function ($a, $v, $f) use ($data) {
                    if ($v == 2 && $data['freight_price'] < 0) {
                        return $f('运费不为空！');
                    }
                },
            ],
        ];
    }

    public function messages()
    {
        return [
            'shareUserId.required' => "分享者ID不能为空！",
            'goodId.required'    => "商品不能为空！",
        ];
    }
}
